package com.chenyue.cm.moudules.system.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.chenyue.cm.system.domain.SysUsers;

public class PasswordHelper {

	private static final String ALGORITH_NAME = "md5";

	private static final int HASH_ITERATIONS = 2;

	public static String encryptPassword(SysUsers sysUsers) {
		String newPassword = new SimpleHash(ALGORITH_NAME, sysUsers.getPassword(),
				ByteSource.Util.bytes(sysUsers.getUsername()), HASH_ITERATIONS).toHex();
		sysUsers.setPassword(newPassword);
		return newPassword;
	}

	public static void main(String[] args) {
		SysUsers sysUsers = new SysUsers();
		sysUsers.setUsername("root");
		sysUsers.setPassword("education");
		PasswordHelper.encryptPassword(sysUsers);
		System.out.println(sysUsers.getPassword());
	}
}